<?php
namespace Home\Controller;
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
use Think\Controller;
class ConfigController extends Controller {
    public function getConfig(){
        $m=M("Config");
        if (IS_POST){
            $data['CompanyId'] = $_POST['companyid'];
            $data['CompanyName'] = $_POST['companyname'];
            $data['Identifier'] = $_POST['identifier'];
            $data['Address'] = $_POST['address'];
            $data['BusinessScope'] = $_POST['businessscope'];
            $data['ContactAddress'] = $_POST['contactaddress'];
            $data['EconomicType'] = $_POST['economictype'];
            $data['RegCapital'] = $_POST['regcapital'];
            $data['LegalName'] = $_POST['legalname'];
            $data['LegalID'] = $_POST['legalid'];
            $data['LegalPhone'] = $_POST['companyid'];
            $data['LegalPhoto'] = $_POST['companyid'];
            $data['State'] = $_POST['state'];
            $data['Flag'] = $_POST['flag'];
            $data['UpdateTime'] = time();
           $res = $m->where(array('id'=>1))->save($data);
           if ($res){
               $ec = 0;
           }else{
               $ec = 1;
           }
           echo $ec;
        }else{
            $configs = M('config')->field('id,CompanyId,CompanyName,Identifier,Address,
            BusinessScope,ContactAddress,EconomicType,RegCapital,LegalName,LegalID,
            LegalPhone,LegalPhoto,State,Flag,UpdateTime')
            ->find();
            C($configs);
            $configs['updatetime'] = date('Y-m-d H:i:s',$configs['updatetime']);
            return $configs;
        }

    }
    public function getMaintain(){
        $m = M('maintain');
        if (IS_POST){
            $_POST['updatetime'] = time();
            $m->create($_POST);
           $res = $m->where(array('id'=>1))->save($_POST);
            if ($res){
                $ec = 0;
            }else{
                $ec = 1;
            }
            echo $ec;
        }else{
            $maintain = M('maintain')->field('id,vehiclenum,drivernum,flag,updatetime')->find();
            if (empty($maintain['updatetime'])){
                $maintain['updatetime'] = '无数据';
            }else{
                $maintain['updatetime'] = date('Y-m-d H:i:s',$maintain['updatetime']);
            }

            return $maintain;
        }

    }
    public function getPayinfo(){
        $pay = M('payinfo');
        if (IS_POST){
            $_POST['updatetime'] = time();
            $data['payname']=$_POST['payname'];
            $data['payid'] = $_POST['payid'];
            $data['paytype'] = $_POST['paytype'];
            $data['payscope'] = $_POST['payscope'];
            $data['preparebank'] = $_POST['preparebank'];
            $data['countdate'] = $_POST['countdate'];
            $data['state'] = $_POST['state'];
            $data['flag'] = $_POST['flag'];
            $data['updatetime'] = time();
            if ($pay->find()){
               $res = $pay->where(array('id'=>1))->save($data);
            }else{
                $res = $pay->add($data);
            }

            if ($res){
                $ec = 0;
            }else{
                $ec = 1;
            }
            echo $ec;
        }else{
            $payinfo = $pay->field('id,payname,payid,paytype,payscope,preparebank,
            countdate,state,flag,updatetime')->find();
            if (empty($payinfo)){
                $payinfo['updatetime'] = '无数据';
            }else{
                $payinfo['updatetime'] = date('Y-m-d H:i:s',$payinfo['updatetime']);
            }

            return $payinfo;
        }

    }
    public function getBuslicense(){
        $m = M('buslicense');
        if (IS_POST){
            $_POST['updatetime'] = time();
            if ($m->find()){
                $res = $m->where(array('id'=>1))->save($_POST);
            }else{
                $res = $m->add($_POST);
            }

            if ($res){
                $ec = 0;
            }else{
                $ec = 1;
            }
            echo $ec;
        }else{
            $buslicense = $m->field('id,certificate,oprationarea,ownername,organization,startdate,
            stopdate,certifydate,state,flag,updatetime')->find();
            if (empty($buslicense)){
                $buslicense['updatetime'] = '无数据';
            }else{
                $buslicense['updatetime'] = date('Y-m-d H:i:s',$buslicense['updatetime']);
            }
            return $buslicense;
        }

    }
    public function getFare(){
        $m = M('fareinfo');
        if (IS_POST){
            $_POST['updatetime'] = time();

            if ($m->find()){
                $res = $m->where(array('id'=>1))->save($_POST);
            }else{
                $res = $m->add($_POST);
            }

            if ($res){
                $ec = 0;
            }else{
                $ec = 1;
            }
            echo $ec;
        }else{
            $fareinfo = $m->field('id,faretype,faretypenote,farevalidon,farevalidoff,startfare,
            startmile,unitpricepermile,unitpriceperminute,upprice,uppricestartmile,morningpeaktimeon,
            morningpeaktimeoff,eveningpeaktimeon,eveningpeaktimeoff,otherpeaktimeon,otherpeaktimeoff,
            peakunitprice,peakpricestartmile,lowspeedpriceperminute,nightpricepermile,nightpriceperminute,
            otherprice,state,updatetime,flag')
                ->find();
            if (empty($fareinfo)){
                $fareinfo['updatetime'] = '无数据';
            }else{
                $fareinfo['updatetime'] = date('Y-m-d H:i:s',$fareinfo['updatetime']);
            }
            return $fareinfo;
        }

    }
    public function getSeragency(){
        $m = M('seragency');
        if (IS_POST){
            $_POST['updatetime'] = time();
            if ($m->find()){
                $res = $m->where(array('id'=>1))->save($_POST);
            }else{
                $res = $m->add($_POST);
            }
            if ($res){
                $ec = 0;
            }else{
                $ec = 1;
            }
            echo $ec;
        }else{
            $seragency = $m->field('id,address,servicename,serviceno,detailaddress,responsiblename,
            responsiblephone,managername,managerphone,contactphone,mailaddress,createdate,state,
            flag,updatetime')->find();
            if (empty($seragency)){
                $seragency['updatetime'] = '无数据';
            }else{
                $seragency['updatetime'] = date('Y-m-d H:i:s',$seragency['updatetime']);
            }
            return $seragency;
        }

    }

    public function getCarpool(){
        $m = M('seragency');
        if (IS_POST){
            $_POST['updatetime'] = time();
            if ($m->find()){
                $res = $m->where(array('id'=>1))->save($_POST);
            }else{
                $res = $m->add($_POST);
            }
            if ($res){
                $ec = 0;
            }else{
                $ec = 1;
            }
            echo $ec;
        }else{
            $seragency = $m->field('id,address,servicename,serviceno,detailaddress,responsiblename,
            responsiblephone,managername,managerphone,contactphone,mailaddress,createdate,state,
            flag,updatetime')->find();
            if (empty($seragency)){
                $seragency['updatetime'] = '无数据';
            }else{
                $seragency['updatetime'] = date('Y-m-d H:i:s',$seragency['updatetime']);
            }
            return $seragency;
        }

    }
}

?>